# 导包
import configparser
# 引进 FILE_PATH 字典
from configs.setting import FILE_PATH
from unit_tools.log_util.recordlog import logs


class ConfigParse:

    def __init__(self, file_path=FILE_PATH['ini']):
        self.file_path = file_path
        self.config = configparser.ConfigParser()
        self.read_config()


    def read_config(self):
        self.config.read(self.file_path)

    def get_value(self, section, option):

        try:
            return self.config.get(section, option)
        except Exception as e:
            logs.error(f'解析配置文件出现异常，原因：{e}')


    def get_host(self, option):
        return self.get_value('Host', option)


    def get_mysql_conf(self, option):
        return self.get_value('MySQL', option)